﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VncSharp;
using System.Collections;

namespace Chat
{
    public partial class FormScreencast : Form
    {
        public FormScreencast()
        {
            InitializeComponent();
        }

        ArrayList ScreencastConversation;
        Timer tmr = new Timer();

        public FormScreencast(string adress)
        {
            InitializeComponent();
            remoteDesktop.Connect(adress, true);
            tmr.Interval = 5000;
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Start();
        }

        void tmr_Tick(object sender, EventArgs e)
        {
            Refresh();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if(remoteDesktop.IsConnected == true)
                remoteDesktop.Disconnect();
            tmr.Stop();
            this.Close();
        }

        private void btnScaled_Click(object sender, EventArgs e)
        {
            if (remoteDesktop.IsConnected == true)
                remoteDesktop.SetScalingMode(false);
        }

        private void bntClipped_Click(object sender, EventArgs e)
        {
            if (remoteDesktop.IsConnected == true)
                remoteDesktop.SetScalingMode(true);
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if (txtMessage.Text != "" || txtMessage.Text != null)
            {
                string Message = txtMessage.Text;

                Global.server.SendScreencastMessage(Global.username, Message);
                txtMessage.Text = "";
            }
            Refresh();
        }

        void Refresh()
        {
            ScreencastConversation = Global.server.GetScreencastConversation();
            txtConversation.Clear();

            foreach (object o in ScreencastConversation)
            {
                txtConversation.AppendText(o.ToString() + "\n");
            }
        }
    }
}
